import Image from "components/Base/Image";
import {memberLevelDict, memberLevelGetName} from "../../../../models/MemberLevel";
import moment from "moment";
import Button from "components/Base/Button";
import Icon from "components/Base/Icon";
import DataTable from "components/Base/DataTable";

export default (self) => [

  {
    title: 'id',
    name: 'id',
    formItem: {
      type: 'hidden',
    }
  },
  {
    title: '用户id',
    name: 'serialNo',
    tableItem: {
    },
  },

  {
    title: '头像',
    name: 'avatarUrl',
    tableItem: {
      render: (text, record) => {
        return <Image src={text} style={{width: 50, height: 50}}/>
      }
    },
  },
  {
    title: '姓名',
    name: 'name',
    tableItem: {},
  },
  {
    title: '手机号',
    name: 'mobile',
    tableItem: {},
  },
  {
    title: '余额',
    name: 'balance',
    tableItem: {},
  },
  {
    title: '性别',
    name: 'gender',
    tableItem: {},
  },
  {
    title: '昵称',
    name: 'nickName',
    tableItem: {},
  },
  {
    title: '省',
    name: 'province',
    tableItem: {},
  },
  {
    title: '城市',
    name: 'city',
    tableItem: {},
  },
  {
    title: '会员等级',
    name: 'memberLevel',
    tableItem: {
      render: (text, record) => {
        const view =
          text == "RESELLER" ?
            <DataTable.Oper>
              <a onClick={e => {
                self.props.showUserDrp(record.id);
              }}>
                <span>{memberLevelGetName(text)}</span>
              </a>
            </DataTable.Oper> :
            <span>{memberLevelGetName(text)}</span>
        return (
          view
        );
      }
    },
    formItem: {
      rules: [
        {
          required: true,
          message: '请选择会员等级'
        }
      ],

      showSearch: true,
      type: 'select',
    },
    dict: memberLevelDict,
  },
  {
    title: '会员到期时间',
    name: 'memberExpireDate',
    tableItem: {},
    formItem: {
      type: 'datetime',
      showTime: true,
      initialValue: moment(),
      format: "YYYY-MM-DD HH:mm:ss"
    }
  },
  {
    title: '操作',
    tableItem: {
      width: 180,
      align: 'center',
      render: (text, record) => (
        <DataTable.Oper>
          <Button tooltip="修改" onClick={e => self.onUpdate(record)}>
            <Icon type="edit"/>
          </Button>
          <Button tooltip="删除" onClick={e => self.onDelete(record)}>
            <Icon type="trash"/>
          </Button>
        </DataTable.Oper>
      )
    }
  }
]
